var content = document.getElementById('pre-content')
patterns.forEach(function (item) {
    var div = document.createElement('div')
    var img = document.createElement('img')
    var p = document.createElement('p')
    div.id = 'pre' + patterns.indexOf(item)
    img.src = item.picPath
    p.textContent = item.name
    div.appendChild(img)
    div.appendChild(p)
    div.addEventListener('click', function (e) {
        clickPre(e.currentTarget.id)
    })
    content.appendChild(div)
})

function clickPre(divId) {
    patterns.forEach(function (item){
        var div = document.getElementById('pre'+patterns.indexOf(item))
        div.style.background = '#ffffff22'
    })
    var currentDiv = document.getElementById(divId)
    currentDiv.style.background = '#4d5eaf22'
    var index = divId[divId.length - 1]
    GLOBAL_CONFIG.currentPattern = patterns[index]
}